#include <iostream>

using namespace std;

class Solution
{
public:
    bool isEqual(char a, char b)
    {
        return tolower(a) == tolower(b);
    }

    bool isNumOrChar(char c)
    {
        return isdigit(c) || isalpha(c);
    }

    bool isPalindrome(string s)
    {
        size_t left = 0, right = s.length() - 1;
        while (left < right)
        {
            if (!isNumOrChar(s[left]))
            {
                left++;
                continue;
            }
            if (!isNumOrChar(s[right]))
            {
                right--;
                continue;
            }
            if (!isEqual(s[left], s[right]))
            {
                return false;
            }
            left++;
            right--;
        }
        return true;
    }
};

int main()
{
    Solution s;
    cout << s.isPalindrome("A man, a plan, a canal: Panama") << endl;
    return 0;
}
